package com.manshutingyu.auth.controller;

import com.manshutingyu.auth.service.LoginService;
import com.manshutingyu.common.core.dto.LoginResultDTO;
import com.manshutingyu.common.core.dto.R;
import com.manshutingyu.common.core.dto.SysUserLoginParamDTO;
import com.manshutingyu.common.core.dto.UserInfoResultDTO;
import feign.Headers;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
*@Author：yinyuxia
*@Date：2025/4/28  09:57
*/
@RestController
//@RequestMapping("/auth")
@Slf4j
public class LoginController {
@Autowired
private LoginService loginService;

    @PostMapping(value = "/login")
    public R<LoginResultDTO> login(@RequestBody SysUserLoginParamDTO sysUserLoginParam) {
        return R.success(loginService.login(sysUserLoginParam.getUsername(), sysUserLoginParam.getPassword()));
    }

    @GetMapping(value = "/info")
    public R<UserInfoResultDTO> getInfo(@RequestHeader("username") String username) {
        UserInfoResultDTO result = loginService.getInfo(username);
        return R.success(result);
    }
    @PostMapping(value = "/logout")
    public R logout(HttpServletRequest request) {
        // 需要 将当前用户token 设置无效
        return R.success();
    }


}
